package com.project.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.SchoolBean;
import com.project.mapper.ISchoolMapper;
import com.project.service.ISchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.7.11
 * Time: 16:13
 * Description: 学校业务层实现类
 */
@Service
@Transactional
public class SchoolServiceImpl implements ISchoolService {
    @Autowired
    private ISchoolMapper iSchoolMapper;

    @Override
    public List<SchoolBean> showSchoolByCity(int cityId) {
        return iSchoolMapper.showSchoolByCity(cityId);
    }

    @Override
    public PageInfo<SchoolBean> showSchoolByItem(int pageNo, String schoolName, int cityId, String statue) {
        PageHelper.startPage(pageNo, 3);
        List<SchoolBean> list = iSchoolMapper.showSchoolByItem(schoolName, cityId, statue);
        PageInfo<SchoolBean> info = PageInfo.of(list);

        return info;
    }

    @Override
    public void addNewSchool(SchoolBean schoolBean) {
        iSchoolMapper.addNewSchool(schoolBean);
    }

    @Override
    public SchoolBean showSchoolInfoById(int schoolId) {
        return iSchoolMapper.showSchoolInfoById(schoolId);
    }

    @Override
    public void updateSchoolStatue(int schoolId) {
        iSchoolMapper.updateSchoolStatue(schoolId, "待审核");
    }

    @Override
    public void passSchoolStatue(int schoolId, String comment) {
        iSchoolMapper.updateSchoolStatue(schoolId, "推广开展");
        iSchoolMapper.updateSchoolComment(schoolId, comment);
    }

    @Override
    public void unPassSchoolStatue(int schoolId, String comment) {
        iSchoolMapper.updateSchoolStatue(schoolId, "审核未通过");
        iSchoolMapper.updateSchoolComment(schoolId, comment);
    }
}
